<?php

/**
 * 验证手机
 * @param $mobile 要验证的手机号码
 * @return true | false
 */
function isMobile($mobile) {
    //$reg = "/^(((13[0-9]{1})|15[0-9]{1}|18[0-9]{1}|)+\d{8})$/";
    $reg = "/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/";
    return preg_match($reg, $mobile);
}

/**
 * 验证邮箱
 * @param $email 要验证的邮箱 
 * @return true | false
 */
function isEmail($email) {
    //$reg = "/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/";
    $reg = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/";
    return preg_match($reg, $email);
}

/**
 * 判断是否为IE浏览器
 * @return true | false
 */
function isIE() {
    $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
    if ((strpos($useragent, 'opera') !== false) || (strpos($useragent, 'konqueror') !== false))
        return false;
    if (strpos($useragent, 'msie ') !== false)
        return true;
    return false;
}

/**
 * 文件下载
 * @param $filepath 文件路径
 * @param $filename 文件名称
 */
function fileDown($filepath, $filename = '') {
    if (!$filename)
        $filename = basename($filepath);
    if (isIE())
        $filename = rawurlencode($filename);
    $filetype = fileext($filename);
    $filesize = sprintf("%u", filesize($filepath));
    if (ob_get_length() !== false)
        @ob_end_clean();
    header('Pragma: public');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: pre-check=0, post-check=0, max-age=0');
    header('Content-Transfer-Encoding: binary');
    header('Content-Encoding: none');
    header('Content-type: ' . $filetype);
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    header('Content-length: ' . $filesize);
    readfile($filepath);
    exit;
}